package cn.itcast.listener;

import cn.itcast.utils.SmsUtils;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.exceptions.ClientException;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

import java.util.Map;

//消息监听器
public class SmsListener implements MessageListener {
    //当队列中有最新消息时会自动执行 onMessage方法
    @Override
    public void onMessage(Message message) {
       //获取消息数据
        byte[] body = message.getBody();
        Map<String,String> map = JSON.parseObject(body, Map.class);
        String signName = map.get("signName");
        String phoneNumbers = map.get("phoneNumbers");
        String templateCode = map.get("templateCode");
        String param = map.get("param");
       // System.out.println(param);
       // System.out.println(phoneNumbers);
       // System.out.println(signName);
       // System.out.println(templateCode);

        //调用工具类发送邮件
      SmsUtils smsUtils = new SmsUtils();
      try {
          smsUtils.sendSms(phoneNumbers,signName,templateCode,param);
      } catch (ClientException e) {
          e.printStackTrace();
      }


    }

}
